package com.example.administrator.yuejian_2.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.administrator.yuejian_2.R;
import com.example.administrator.yuejian_2.bean.CommentListBean;
import com.example.administrator.yuejian_2.viewholder.CommentListVH;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/10/13.
 */

public class CommentListAdapter extends RecyclerView.Adapter {
    private List<CommentListBean> commentList = new ArrayList<>();
    private Context context;
    private LayoutInflater layoutInflater;

    public CommentListAdapter(Context context,List<CommentListBean> commentList){
        this.context = context;
        layoutInflater = LayoutInflater.from(context);
        this.commentList.addAll(commentList);

    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = layoutInflater.inflate(R.layout.item_comment,parent,false);
        CommentListVH holder = new CommentListVH(itemView);
        return holder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        CommentListVH commentListVH = (CommentListVH) holder;
        CommentListBean commentListBean = commentList.get(position);

        String name = commentListBean.getU_name();
        commentListVH.uname.setText(name);

        String time = commentListBean.getTime();
        commentListVH.utime.setText(time);

        String title = commentListBean.getContent();
        commentListVH.commentcontent.setText(title);

        String pic = commentListBean.getU_pic();
        if (!pic.equals(""))
            Picasso.with(context)
                    .load("http://10.0.2.2/YueJian16/Public/photo/"+pic)
                    .into(commentListVH.roundedImageView);

    }

    @Override
    public int getItemCount() {

        return commentList.size();
    }
}
